import java.util.Scanner;
public class MaxSub{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入数组大小: ");
int n = scanner.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
}
System.out.println("最大子序列和为: " + MaxSum(arr));
scanner.close();
}
public static int MaxSum(int[] a) {
    int sum = 0;
    int max = a[0];
    for (int i = 0; i < a.length; i++) {
        sum = sum + a[i];
        if (sum < a[i]) {
            sum = a[i];
        }
        if (sum > max) {
            max = sum;
        }
    }
    return max;
}
}